﻿using Common.EntityValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestMvc.Models;

namespace TestMvc.Controllers
{
    public class HomeController : Controller
    {
       

        public ActionResult Create(Student student)
        {

            #region
            var defaulVali = EntifyValidator.Validate(student);// 验证实体，默认验证所有字段
            #endregion



            #region
            var  IgnoreVali = EntifyValidator.Validate(student,"ClassId");// 验证实体，跳过字段ClassId的验证
            #endregion


            #region
            var r2 = EntifyValidator.ValidateQuickly(student);//快速验证，当有不通过的字段时，立即返回

            #endregion
            #region

            string pwd = Request["Pwd"];   

            var vPwd = StrongPassWordAttribute.IsValid(pwd); //验证单个value，验证是否强密码

            if (!vPwd.IsValid) 
            {

                return Content(vPwd.ErrorMessage);   //这不是一个强密码
            }

            #endregion


            if (defaulVali.IsValid)   //返回true或者false
            {

                return Content(defaulVali.ErrorMessage);
            }
            //TODO
            return Content("");
        }


    }


    //自定义
    public class CustomAttribute:ValidationAttribute
    {


        public override bool Verify(object o)
        {
            //这里写验证逻辑


            return false;
        }

    }
}